package com.icim.twqc.exporter.service;

import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.icim.twqc.exporter.entity.Prod_defect;
import com.icim.twqc.exporter.entity.Prod_ecoa;
import com.icim.twqc.exporter.entity.Prod_spc;
import com.icim.twqc.exporter.tx.TwqcShippingO;
import com.icim.twqc.importer.entity.TwqcMfgFileXmlEntity;
import com.icim.twqc.importer.entity.TwqcMfgInfoXmlEntity;
import com.icim.core.service.IAlarmSenderService;
import com.icim.core.service.IFtpTwqcService;
import com.icim.dao.BisDataDao;
import com.icim.dao.BisMdlDefDao;
import com.icim.dao.HisRetPrdInfoDao;
import com.icim.dao.RetBoxDao;
import com.icim.dao.RetPrdCutDao;
import com.icim.dao.RetPrdInDao;
import com.icim.dao.RetPrdInTwqcDao;
import com.icim.dao.RetPrdInfoDao;
import com.icim.dao.RetPrdJgeDao;
import com.icim.dao.RetWoDao;
import com.icim.dao.SpcRetMfgDataDao;
import com.icim.entity.Bis_data;
import com.icim.entity.Bis_mdl_def;
import com.icim.entity.His_ret_prd_info;
import com.icim.entity.Ret_box;
import com.icim.entity.Ret_prd_cut;
import com.icim.entity.Ret_prd_in;
import com.icim.entity.Ret_prd_in_twqc;
import com.icim.entity.Ret_prd_info;
import com.icim.entity.Ret_prd_jge;
import com.icim.entity.Ret_wo;
import com.icim.entity.Spc_ret_mfg_data;
import com.icim.util.CsvFileWriterUtil;
import com.icim.util.FileUtil;
import com.icim.util.TimeUtil;
import com.icim.util.XmlConvertUtil;
import com.icim.util.ZipCompressUtil;
import com.icim.xmtm005.entity.CtSlimifRetDefectData005;


@Service
public class TwqcExportShippingDataService implements ITwqcExportShippingDataService {
	
	
	@Resource
	private RetBoxDao retboxdao;
	
	@Resource
	private SpcRetMfgDataDao SpcRetMfgDataDao;
	
	@Resource
	private RetPrdInDao retprdindao;
	
	@Resource
	private RetPrdInfoDao retprdinfodao;
	
	@Resource
	private RetPrdJgeDao retPrdJgedao;
	
	@Resource
	private RetPrdInTwqcDao retprdintwqcdao;
	
	@Resource
	private RetPrdCutDao retprdcutdao;
	
	@Resource
	private BisDataDao bisDataDao;
	
	@Resource
	private RetWoDao retwodao;
	
	@Resource
	private HisRetPrdInfoDao hisRetPrdInfoDao;
	
	@Resource
	private RetPrdInDao retProductInDao;
	
	@Resource
	private BisMdlDefDao bisMdlDefDao;
	
	@Resource
	private IFtpTwqcService ftpTwqcService;
	@Resource
    private IAlarmSenderService alarmSenderService;
	
	private Logger logger = LoggerFactory.getLogger(TwqcExportShippingDataService.class);
	private int randomNum = 0;
	//用于上传到服务器
	private File IFDBgzFile;
	private File DEFECTgzFile;
	private File SPCgzFile;
	private File ECOAgzFile;
	private boolean IFDBFlag = true;
	private boolean DEFECTFlag = true;
	private boolean SPCFlag = true;
	private boolean ECOAFlag = true;
	private String palletId = "";
	public String subMainProc(String palletId) throws Exception {
        String rtnMsg = "";
        /*try {*/
        	//初始化
      		IFDBFlag = true;
      		DEFECTFlag = true;
      		SPCFlag = true;
      		ECOAFlag = true;
      		/*IFDBgzFile = new File("");
      		DEFECTgzFile = new File("");
      		SPCgzFile = new File("");
      		ECOAgzFile = new File("");*/
            logger.info(palletId);
            rtnMsg =  subMainProc2(palletId);
        /*} catch (Exception e) {
            logger.error(e.toString());
            alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+e.toString());
            TwqcShippingO outTrx = new TwqcShippingO();
            outTrx.setTrx_id("TWQCSHIPPING");
            outTrx.setType_id("O");
            outTrx.setRtn_code("9999999");
            outTrx.setRtn_mesg(e.toString());
            rtnMsg = outTrx.toString();
            throw e;
        }*/
        return rtnMsg;
    }
	
	public String subMainProc2(String palletId) throws Exception {
		
		
	
		TwqcShippingO outTrx = new TwqcShippingO();
        outTrx.setTrx_id("TWQCSHIPPING");
        outTrx.setType_id("O");
        outTrx.setRtn_code("0000000");
        outTrx.setRtn_mesg("SUCCESS");
        
        if (StringUtils.isEmpty(palletId)) {
            outTrx.setRtn_code("0000002");
            outTrx.setRtn_mesg("栈板ID不能为空");
            return XmlConvertUtil.obj2Xml(outTrx, "transaction");
        }
        
        TwqcMfgFileXmlEntity mfgFileXmlEntity = new TwqcMfgFileXmlEntity();
        List<TwqcMfgInfoXmlEntity> mfgInfoXmlEntityList = new ArrayList<TwqcMfgInfoXmlEntity>();
     // 根据palletId找到箱子
        List<Ret_box> retBoxList = retboxdao.getBoxList(palletId);
        if (retBoxList.isEmpty()) {
            outTrx.setRtn_code("9999999");
            outTrx.setRtn_mesg("can not find any box by pallet id");
            return XmlConvertUtil.obj2Xml(outTrx, "transaction");
        }
        logger.info("find {} records in ret_box.....",retBoxList.size());
        for(Ret_box retBox : retBoxList)
        {
        	List<Ret_prd_info> prd_info_List = retprdinfodao.getSheetList(retBox.getBox_id());
        	for(Ret_prd_info prd_info : prd_info_List)
        	{
        		TwqcMfgInfoXmlEntity mfgInfoXmlEntity = new TwqcMfgInfoXmlEntity();
        		mfgInfoXmlEntity.init();
        		String product_id = prd_info.getPrd_seq_id().split("_")[0];
        		List<Ret_prd_cut> ret_prd_cut_List = retprdcutdao.getCutListByPID(product_id);
        		logger.info("find records in Ret_prd_cut 》"+ret_prd_cut_List);
        		Ret_prd_in_twqc prd_in_twqc = new Ret_prd_in_twqc();
        		prd_in_twqc.init();
        		if(ret_prd_cut_List.size()!=0){
        			String SUB_prd_id = ret_prd_cut_List.get(0).getPV_PRD_SEQ_ID().split("_")[0];
            		//拿到大片的玻璃id，然后直接去客户来料表中找没有背景栏位的数据
            		List<Ret_prd_in_twqc> prd_in_twqc_List = retprdintwqcdao.getRetPrdInListByPId(SUB_prd_id);
            		logger.info("find records in ret_prd_in_twqc ....."+prd_in_twqc_List);
            		if(prd_in_twqc_List.size()==0)
            			logger.info("WARNING！未在来料表中找到玻璃id为["+SUB_prd_id+"]的数据");
            		prd_in_twqc = prd_in_twqc_List.get(0);
        		}else{
        			//cut表中没有数据，直接去来料表中取
        			List<Ret_prd_in_twqc> prd_in_twqc_List = retprdintwqcdao.getRetPrdInListByPId(product_id);
        			if(prd_in_twqc_List.size()!=0){
            			prd_in_twqc = prd_in_twqc_List.get(0);
        			}
        		}
        		
        		//============================无背景栏位直接带回客户资料======================
        		
        		setXmlEntity(mfgInfoXmlEntity,prd_in_twqc);
        		
        		//==========================黄色背景栏位取值===============================
        		//TODO	修改时间格式
    			mfgInfoXmlEntity.setSHIPPINGDATE(getFormatTimeStr(prd_info.getShipping_timestamp().toString()));
                mfgInfoXmlEntity.setPALLET_ID(palletId);
                //直接取得箱子表中的ext_8字段，物理箱号
                mfgInfoXmlEntity.setCARTON_ID(retBox.getBoxrealid());
                mfgInfoXmlEntity.setPRODUCTID(retBox.getMdl_id());
                //mfgInfoXmlEntity.setPPBOX_GRADE(prd_info.getGrade());
                mfgInfoXmlEntity.setGLASS_QTY(retBox.getPrd_qty());
                String type = prd_info.getPrd_seq_typ();
                if(type.equals("S")){
                	mfgInfoXmlEntity.setGSFLAG("SUB");
                }
                else if(type.equals("M"))
                {
                	mfgInfoXmlEntity.setGSFLAG("CUT");
                }
                else if(type.equals("P")){
                	mfgInfoXmlEntity.setGSFLAG("PNL");
                }
                //mfgInfoXmlEntity.setCHIP_QTY(prd_info.getX_axis_cnt() * prd_info.getY_axis_cnt());
                String glassId = prd_info.getPrd_seq_id().split("_")[0];
                if(prd_info.getPrd_seq_typ().equals("M") && prd_info.getMdl_id_fk().equals("2422A1013503H")){
                	glassId = glassId.substring(0, glassId.length()-2);
                }
                mfgInfoXmlEntity.setGLASSID(glassId);
                mfgInfoXmlEntity.setSLOT_NO(prd_info.getSlot_no());
                mfgInfoXmlEntity.setX(prd_info.getX_axis_cnt());
                mfgInfoXmlEntity.setY(prd_info.getY_axis_cnt());
                mfgInfoXmlEntity.setPP_BOX_ID(retBox.getShip_box_id()==null?"":retBox.getShip_box_id());
        		
                //=============橙色背景栏位取值================================
                //需要先对工单进行判断，如果是M需要mapping，如果是S不需要mapping直接回传
                //String plantID = retwodao.getWo(retBox.getWo_id_fk()).get(0).getPlantID();
                if(prd_info.getPrd_seq_typ().equals("M")){
                	cutGlassProc(prd_info,mfgInfoXmlEntity,prd_in_twqc);
                    if (IFDBFlag == false) {
                        outTrx.setRtn_code("0000002");
                        outTrx.setRtn_mesg("length is short,see the log info");
                        return XmlConvertUtil.obj2Xml(outTrx, "transaction");
                    }
                }
                //=========================================
                mfgInfoXmlEntityList.add(mfgInfoXmlEntity);
        	}
        }
        
        String fileName = getFileName();
        mfgFileXmlEntity.setFILENAME(fileName);
        mfgFileXmlEntity.setMFGINFO(mfgInfoXmlEntityList);
        mfgFileXmlEntity.setRECEIVERID("INX");
        mfgFileXmlEntity.setSENDERID("WGT");
        if(IFDBFlag == true && DEFECTFlag == true && SPCFlag == true && ECOAFlag == true){
			// 将对象转换成xml
	        logger.info("开始生成xml文件。。。");
	        String xml = XmlConvertUtil.obj2XmlFor232(mfgFileXmlEntity, "MFGFILE");
	        logger.info(xml);
	        
	        //String localPath = ftpTwqcService.getFtpConfigure().getLocalTemporaryPath().trim();
	        String localPath = ftpTwqcService.getFtpConfigure().getLocalGzPath();
	        String xmlFileName = localPath + "/" + fileName;
	        FileUtil.sting2File(xmlFileName, xml);
	        // 压缩zip包

	        ZipCompressUtil.compress(new File(xmlFileName));
	        // 上传ftp

	        String gzFileName = xmlFileName + ".zip";
	        IFDBgzFile = new File(gzFileName);
	        /*ftpTwqcService.connect();
	        ftpTwqcService.uploadFile(gzFile);
	        flag = true;
	        //在此处可以对OUT目录下的XML压缩包文件进行删除
	        ftpTwqcService.disconnectFtp();*/
		}
        return XmlConvertUtil.obj2Xml(outTrx, "transaction");
	}
	
	
	
	
	/*
	 * 回传defect、spc、箱子良率等信息
	 */
	@Override
	public TwqcShippingO sendShippingData(String palletId)
			throws Exception {
		TwqcShippingO outTrx = new TwqcShippingO();
		List<Ret_box> boxList = retboxdao.getBoxList(palletId);
		logger.info("find {} records in ret_box.....",boxList.size());
		List<Prod_defect> DefectEntityList = new ArrayList<Prod_defect>();
		List<Prod_spc> SpcEntityList = new ArrayList<Prod_spc>();
		List<Prod_ecoa> EcoaEntityList = new ArrayList<Prod_ecoa>();
		if(boxList.size()!=0)
		{
			for(Ret_box retBox : boxList)
			{
				String boxid = retBox.getBox_id();
				List<Ret_wo> ret_wo_List = retwodao.getWo(retBox.getWo_id_fk());
				List<Ret_prd_info> ret_prd_info_List = retprdinfodao.getSheetList(boxid);
				Set<String> sheetIdSet = new HashSet<String>();
				for (Ret_prd_info rePrdInfo : ret_prd_info_List) {
					sheetIdSet.add(rePrdInfo.getPrd_seq_id());
				}
				Map<String, List<Ret_prd_jge>> defectSheetMap = retPrdJgedao.getDefectMapBySheets(sheetIdSet);
				
				for (int i = 0; i < ret_prd_info_List.size(); i++) {
					Ret_prd_info sheet = ret_prd_info_List.get(i);
					String sheetId = sheet.getPrd_seq_id();
					List<Ret_prd_jge> defectList = defectSheetMap.get(sheetId);
					if (defectList != null && !defectList.isEmpty()) {
						for (Ret_prd_jge defect : defectList) {
							if (defect.getDef_code1_cnt() == -1) {
								continue;
							} else {
								boolean existFlg = false;
								for (Ret_prd_jge defect2 : defectList) {
									if (defect2.getDef_code1_lc().equals(defect.getDef_code1_lc())
											&& defect2.getDef_code1_sd().equals(defect.getDef_code1_sd())
											&& defect2.getDef_code1().equals(defect.getDef_code1())
											&& defect2.getDef_code1_cnt() == -1) {
										existFlg = true;
										break;
									}
								}

								if (existFlg) {
									continue;
								}
							}
							//====================回传产品不良信息==============================
							Prod_defect DefectEntity = new Prod_defect();
							DefectEntity.setSUPPLIER("WGT");
							String mdl_cate_fk = ret_wo_List.get(0).getMdl_cate_fk();
				            if(mdl_cate_fk.equals("A"))
				            {
				            	//减薄后型号
				            	DefectEntity.setPPRO_ID(ret_wo_List.get(0).getMdl_id_fk());
				            }
				            else if(mdl_cate_fk.equals("AB") || mdl_cate_fk.equals("B"))
				            {
				            	//镀膜后型号
				            	DefectEntity.setPPRO_ID(ret_wo_List.get(0).getFm_mdl_id_fk());
				            }
				            else if(mdl_cate_fk.equals("AC") || mdl_cate_fk.equals("ABC") || mdl_cate_fk.equals("BC") || mdl_cate_fk.equals("C"))
				            {
				            	//切割后型号
				            	DefectEntity.setPPRO_ID(ret_wo_List.get(0).getCut_mdl_id_fk());
				            }
				            Ret_prd_info prd_info = retprdinfodao.getInforById(defect.getPrd_seq_id_fk());
				            String glassId = prd_info.getPrd_seq_id().split("_")[0];
			                if(prd_info.getPrd_seq_typ().equals("M") && prd_info.getMdl_id_fk().equals("2422A1013503H")){
			                	glassId = glassId.substring(0, glassId.length()-2);
			                }
							DefectEntity.setCUT_ID(glassId);
							DefectEntity.setDEFECT_CODE(defect.getDef_code1());
							//String position_X = ret_prd_jge.getDef_code1_lc().substring(0, 1);
							//String position_Y = ret_prd_jge.getDef_code1_lc().substring(2);
							DefectEntity.setDEFECT_POS(defect.getDef_code1_lc());
							//不良描述 TODO
							List<Bis_data> bis_data_List = bisDataDao.listData("DFCT", defect.getDef_code1(), "", "", "", "", "", "", "");
							DefectEntity.setDEFECT_DSC(bis_data_List.get(0).getData_ext());
							DefectEntity.setOPEID(defect.getOpe_id_fk());
							
							DefectEntityList.add(DefectEntity);
						}
					}
				}
				
				//=======================回传产品SPC信息============================
				
				
				
				for(Ret_prd_info ret_prd_info : ret_prd_info_List)
				{
					Prod_spc SpcEntity = new Prod_spc();
					List<His_ret_prd_info> hisRetPrdInfoList = hisRetPrdInfoDao.findSheets(ret_prd_info.getPrd_seq_id());
					//抛光压力
					List<Spc_ret_mfg_data> spcDataList1 = SpcRetMfgDataDao.getCsotSpcDataRecordersForRet005(ret_prd_info.getPrd_seq_id());
					if(spcDataList1.size()!=0)
					{
						Spc_ret_mfg_data spcData1 = spcDataList1.get(0);
						//TODO 抛光压力
						SpcEntity.setPOLISH_PRESSURE(spcData1.getData_value_002());
						//TODO 
						SpcEntity.setPOLISH_TIME(spcData1.getData_value_007());
					}
					//获取大板的信息
					String mtrl_box_id = "";
	                if(ret_prd_info.getPrd_seq_typ().equals("S")){
	                	//大板类型，不切割
	                	mtrl_box_id = ret_prd_info.getMtrl_box_id_fk();
	                }else{
	                	Ret_prd_info pv_retPrdInfo = retprdinfodao.getInforById(ret_prd_info.getPv_prd_seq_id());
	                	mtrl_box_id = pv_retPrdInfo.getMtrl_box_id_fk();
	                }
	                
					
					//
					Timestamp in_time = ret_wo_List.get(0).getBnd_box_timestamp();
					SpcEntity.setSUPPLIER("WGT");
					
					SpcEntity.setOUT_DATE(getFormatTimeStr2(ret_prd_info.getShipping_timestamp()));
					SpcEntity.setPRODUCT_ID(retBox.getMdl_id());
					//取值为出货箱的物理箱号
					SpcEntity.setFS_CARTON_ID(retBox.getBoxrealid());
					SpcEntity.setPP_BOX_ID(retBox.getShip_box_id());
					//取值为来料箱号对应的物理箱号
					Ret_box retBox2 = new Ret_box();
					retBox2 = retboxdao.getBoxListByBoxId(mtrl_box_id).get(0);
					if(null==retBox2){
						logger.info("回传SPC信息失败，未找到箱号为["+mtrl_box_id+"]的箱子");
					}
					SpcEntity.setINX_CARTON_ID(retBox2.getBoxrealid());
		            String glassId = ret_prd_info.getPrd_seq_id().split("_")[0];
	                if(ret_prd_info.getPrd_seq_typ().equals("M") && ret_prd_info.getMdl_id_fk().equals("2422A1013503H")){
	                	glassId = glassId.substring(0, glassId.length()-2);
	                }
					SpcEntity.setSHEET_ID(glassId);
					SpcEntity.setPRODUCTGRADE(ret_prd_info.getPrd_grade());
					boolean flag = false;
					for(His_ret_prd_info hisRetPrdInfo : hisRetPrdInfoList)
					{
						
						String evt_cate = hisRetPrdInfo.getEvt_cate();
						String cr_proc_id = hisRetPrdInfo.getCr_proc_id_fk();
						String cr_ope_id = hisRetPrdInfo.getCr_ope_id_fk();
						if(cr_proc_id.equals("JBIC") && evt_cate.equals("LGOF"))
						{
							SpcEntity.setIQC_USER(hisRetPrdInfo.getEvt_usr());
						}
						if(cr_proc_id.equals("DJGH") && evt_cate.equals("LGOF"))
						{
							//TODO 封胶人员编号
							SpcEntity.setSEAL_USER(hisRetPrdInfo.getEvt_usr());
						}
						if(cr_proc_id.equals("JBZJ") && evt_cate.equals("LGOF"))
						{
							SpcEntity.setOQC_USER(hisRetPrdInfo.getEvt_usr());
						}
						if(cr_proc_id.equals("JBSK") && evt_cate.equals("LGOF"))
						{//蚀刻机编号
							SpcEntity.setETCHING_NO(hisRetPrdInfo.getCr_tool_id_fk());
						}
						if(cr_proc_id.equals("JBPG") && evt_cate.equals("LGOF"))
						{
							SpcEntity.setPOLISH_NO(hisRetPrdInfo.getCr_tool_id_fk());
						}
						
						if(cr_ope_id.equals("DM-01") || cr_ope_id.equals("DM-02"))
						{
							//TODO 清洗机编号
							if(flag == false)
							{SpcEntity.setCLEAN_NO(hisRetPrdInfo.getCr_tool_id_fk());
							flag = true;
							}
						}
						
					}
					List<His_ret_prd_info> hisRetPrdInfoList1 = new ArrayList<His_ret_prd_info>();
					if(ret_prd_info.getPrd_seq_typ().equals("S")){
						hisRetPrdInfoList1 = hisRetPrdInfoDao.findSheets(ret_prd_info.getPrd_seq_id());
					}else{
						hisRetPrdInfoList1 = hisRetPrdInfoDao.findSheets(ret_prd_info.getPv_prd_seq_id());
					}
					Ret_prd_in prd_in = retprdindao.getBoxListByBoxId(ret_prd_info.getMtrl_box_id_fk()).get(0);
					
					SpcEntity.setIN_DATE(getFormatTimeStr2(prd_in.getRcv_timestamp()));
					boolean flag0 = false;
					for(His_ret_prd_info hisRetPrdInfo : hisRetPrdInfoList1)
					{
						String cr_ope_id = hisRetPrdInfo.getCr_ope_id_fk();
						
						if(cr_ope_id.equals("FQ-01"))
						{
							//TODO 切割机编号
							if(flag0 == false)
							{
								SpcEntity.setCUTTING_NO(hisRetPrdInfo.getCr_tool_id_fk());
								flag0 = true;
							}
							
						}
					}
					//厚度
					List<Spc_ret_mfg_data> spcDataList = new ArrayList();
					if(ret_prd_info.getPrd_seq_typ().equals("S")){
						spcDataList = SpcRetMfgDataDao.getTwqcSpcDataRecorders(ret_prd_info.getPrd_seq_id());
					}else{
						spcDataList = SpcRetMfgDataDao.getTwqcSpcDataRecorders(ret_prd_info.getPv_prd_seq_id());
					}
					if(spcDataList!=null && spcDataList.size()!=0)
					{
						Spc_ret_mfg_data spcData = spcDataList.get(0);
						
						SpcEntity.setTHICKNESS_1(spcData.getData_value_001());
						SpcEntity.setTHICKNESS_2(spcData.getData_value_002());
						SpcEntity.setTHICKNESS_3(spcData.getData_value_003());
						SpcEntity.setTHICKNESS_4(spcData.getData_value_004());
						SpcEntity.setTHICKNESS_5(spcData.getData_value_005());
						SpcEntity.setTHICKNESS_6(spcData.getData_value_006());
						SpcEntity.setTHICKNESS_7(spcData.getData_value_007());
						SpcEntity.setTHICKNESS_8(spcData.getData_value_008());
					}
					
					SpcEntityList.add(SpcEntity);
				}
				
				//=======================以出货箱号回传产品信息======================
				
				
				Prod_ecoa EcoaEntity = new Prod_ecoa();
				EcoaEntity.setSUPPLIER("WGT");
				EcoaEntity.setPRODUCT_ID(retBox.getMdl_id());
				EcoaEntity.setCARTON_ID(retBox.getShip_box_id());
				EcoaEntity.setTARGET_THICKNESS(String.valueOf(ret_wo_List.get(0).getTo_thickness()*1000)+"um");
				EcoaEntity.setIN_QTY_SHT(String.valueOf(retBox.getPrd_qty()));
				EcoaEntity.setIN_NG_SHT_NON_PRCS("0");
				int LC = 0;
				int LK = 0;
				int GK = 0;
				int LY = 0;
				int SC = 0;
				int OK = 0;
				int thick_num = 0;
				int Sum = 0;
				int OkSum = 0;
				for(Ret_prd_info ret_prd_info : ret_prd_info_List)
				{//统计不良产品数量
					if(ret_prd_info.getPrd_grade().equals("LC"))
					{LC++;}
					if(ret_prd_info.getPrd_grade().equals("LK"))
					{LK++;}
					if(ret_prd_info.getPrd_grade().equals("GK"))
					{GK++;}
					if(ret_prd_info.getPrd_grade().equals("LY"))
					{LY++;}
					if(ret_prd_info.getPrd_grade().equals("SC"))
					{SC++;}
					//统计箱内玻璃的ok数
					if(ret_prd_info.getPrd_grade().equals("OK"))
					{OK++;}
					/*if(ret_prd_info.getPrd_admin_flg().substring(2,3).equals("Y"))
					{thick_num++;}*/
					//统计出货的玻璃总粒数
					Sum = Sum+ret_prd_info.getPrd_qty();
					OkSum = OkSum+ret_prd_info.getPrd_std_qty();
					boolean thickFlag = false;
					//统计厚度异常
					List<Ret_prd_jge> ret_prd_jge_List = retPrdJgedao.getDefProductByPID(ret_prd_info.getPrd_seq_id().split("_")[0]);
					for(Ret_prd_jge ret_prd_jge : ret_prd_jge_List)
					{
						if(ret_prd_jge.getDef_code1().equals("Z012") || ret_prd_jge.getDef_code1().equals("Z013"))
						{
							thickFlag = true;
						}
					}
					if(thickFlag == true)
					{
						thick_num++;
					}
				}
				EcoaEntity.setIN_QTY_PANEL(String.valueOf(OkSum));
				EcoaEntity.setIN_NEED_REPAIR_SHT(String.valueOf(LC));
				EcoaEntity.setIN_NG_SHT_BREAK(String.valueOf(LK));
				EcoaEntity.setETCH_QTY_SHT(String.valueOf(retBox.getPrd_qty()));
				EcoaEntity.setETCH_QTY_PANEL(String.valueOf(OkSum));
				EcoaEntity.setETCH_QTY_NG_SHT_BREAK(String.valueOf(GK));
				EcoaEntity.setETCH_QTY_NG_SHT_LEAK(String.valueOf(LY));
				EcoaEntity.setETCH_QTY_NG_SHT_CRACK(String.valueOf(SC));
				EcoaEntity.setTHICK_OVER_SPEC_SHT(String.valueOf(thick_num));
				//Double sheet_yeild = (double)OK/retBox.getPrd_qty();
				//Double panel_yeild = (double)Sum/OkSum;
				String resultStr_sheet = String.format("%.4f",(double)OK/retBox.getPrd_qty());
				String resultStr_panel = String.format("%.4f",(double)Sum/OkSum);
				if(OK==retBox.getPrd_qty() || resultStr_sheet.equals("1.0000")){
					EcoaEntity.setSHEET_YIELD("100%");
				}else{
					EcoaEntity.setSHEET_YIELD(resultStr_sheet.substring(2, 4)+"."+resultStr_sheet.substring(4,6)+"%");
				}
				if(Sum==OkSum || resultStr_panel.equals("1.0000")){
					EcoaEntity.setPANEL_YIELD("100%");
				}else{
					EcoaEntity.setPANEL_YIELD(resultStr_panel.substring(2, 4)+"."+resultStr_panel.substring(4,6)+"%");
				}
				EcoaEntity.setTPO_SHT_IN_SPEC(String.valueOf(GK));
				EcoaEntity.setTPO_SHT_OUT_SPEC(String.valueOf(SC));
				EcoaEntity.setSUPPLIER_SHT_IN_SPEC(String.valueOf(LC));
				EcoaEntity.setSUPPLIER_SHT_OUT_SPEC(String.valueOf(LK));
				EcoaEntity.setLOT_TYPE(ret_wo_List.get(0).getWo_cate());
				
				EcoaEntityList.add(EcoaEntity);
					
				
			}
			if(IFDBFlag == true && DEFECTFlag == true && SPCFlag == true && ECOAFlag == true){
				//全部赋值完成，开始导出文件
				logger.info("find {} defect records....",DefectEntityList.size());
				logger.info("find {} spc records....",SpcEntityList.size());
				logger.info("find {} ecoa records....",EcoaEntityList.size());
				
				if(DefectEntityList.size() != 0)
				{
					generateCSV(DefectEntityList,null,null,"DEFECT");
				}
				if(SpcEntityList.size() != 0)
				{
					generateCSV(null,SpcEntityList,null,"SPC");
				}
				if(EcoaEntityList.size() != 0)
				{
					generateCSV(null,null,EcoaEntityList,"ECOA");
				}
			}
		}
		//本地文件全部生成成功，开始上传到服务器
		//TODO
		if(IFDBFlag == true && ECOAFlag == true && DEFECTFlag == true && SPCFlag == true)
		{
			ftpTwqcService.connect();
			if(IFDBgzFile.exists()){
		        ftpTwqcService.uploadFile(IFDBgzFile);
			}
			if(DEFECTgzFile.exists()){
		        ftpTwqcService.uploadFile(DEFECTgzFile, ftpTwqcService.getFtpConfigure().getFtpDefectExportPath());
			}
			if(SPCgzFile.exists()){
		        ftpTwqcService.uploadFile(SPCgzFile, ftpTwqcService.getFtpConfigure().getFtpSpcExportPath());
			}
			if(ECOAgzFile.exists()){
		        ftpTwqcService.uploadFile(ECOAgzFile, ftpTwqcService.getFtpConfigure().getFtpEcoaExportPath());
			}
	        ftpTwqcService.disconnectFtp();
	       
		}else{
			//删除之前生成成功的文件
			/*if(IFDBgzFile.exists()){
				IFDBgzFile.delete();
			}
			if(DEFECTgzFile.exists()){
				DEFECTgzFile.delete();
			}
			if(SPCgzFile.exists()){
				SPCgzFile.delete();
			}
			if(ECOAgzFile.exists()){
				ECOAgzFile.delete();
			}*/
		}
        
		outTrx.setRtn_code("0000000");
		outTrx.setRtn_mesg("SUCCESS");
		return outTrx;
	}
	
	public void generateCSV(List<Prod_defect> DefectEntityList,List<Prod_spc> SpcEntityList,List<Prod_ecoa> EcoaEntityList,String type) throws Exception
	{
		if(type.equals("DEFECT"))
		{
			List<String[]> bodyList = new ArrayList<String[]>();
	        for (Prod_defect entity : DefectEntityList) {
	            String[] body = new String[] { entity.getSUPPLIER(),entity.getPPRO_ID(),entity.getCUT_ID(),
	            		entity.getDEFECT_CODE(),entity.getDEFECT_POS(),entity.getDEFECT_DSC(),entity.getOPEID()};
	            logger.info(entity.toString());
	            bodyList.add(body);
	        }
			try {
				String fileName = ftpTwqcService.getFtpConfigure().getLocalDefectGzPath().trim()+"/PROD_DEFECT_" + getCurrentTimeStr() + ".csv";
				String[] headers = { "SUPPLIER", "PPRO_ID", "CUT_ID", "DEFECT_CODE", "DEFECT_POS", "DEFECT_DSC","OPEID" };
	            logger.info("building twqc_defect csv file process [" + fileName + "]");
	            CsvFileWriterUtil.writeCVS("SLIM_DEFECT_DATA_BEGIN", headers, bodyList, "SLIM_DEFECT_DATA_END", fileName);
	            logger.info("compress twqc_defect csv file process ....");
	            
	            ZipCompressUtil.compress(new File(fileName));
	            String gzFileName = fileName + ".zip";
	            DEFECTgzFile = new File(gzFileName);

	            // send to FTP Service
		            /*ftpTwqcService.connect();
		            ftpTwqcService.uploadFile(gzFile, ftpTwqcService.getFtpConfigure().getFtpDefectExportPath());
		            ftpTwqcService.disconnectFtp();*/
	           // logger.info("=============================================================================");
	        } catch (Exception e) {
	        	DEFECTFlag = false;
	        	e.printStackTrace();
	            logger.error(e.toString());
	            alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+e.toString());
	            throw e;
	        }
		}
		else if(type.equals("SPC"))
		{
			List<String[]> bodyList = new ArrayList<String[]>();
	        for (Prod_spc entity : SpcEntityList) {
	            String[] body = new String[] {entity.getSUPPLIER(),entity.getIN_DATE(),entity.getOUT_DATE(),
	            		entity.getPRODUCT_ID(),entity.getFS_CARTON_ID(),entity.getPP_BOX_ID(),entity.getINX_CARTON_ID(),
	            		entity.getSHEET_ID(),entity.getPRODUCTGRADE(),entity.getIQC_USER(),entity.getSEAL_USER(),
	            		entity.getOQC_USER(),entity.getETCHING_NO(),entity.getPOLISH_NO(),entity.getPOLISH_PRESSURE(),
	            		entity.getPOLISH_TIME(),entity.getCUTTING_NO(),entity.getCLEAN_NO(),entity.getTHICKNESS_1(),
	            		entity.getTHICKNESS_2(),entity.getTHICKNESS_3(),entity.getTHICKNESS_4(),entity.getTHICKNESS_5(),
	            		entity.getTHICKNESS_6(),entity.getTHICKNESS_7(),entity.getTHICKNESS_8()};
	            logger.info(entity.toString());
	            bodyList.add(body);
	        }
			try {
				String fileName = ftpTwqcService.getFtpConfigure().getLocalSpcGzPath().trim()+"/PROD_SPC_" + getCurrentTimeStr() + ".csv";
				String[] headers = { "SUPPLIER", "IN_DATE", "OUT_DATE", "PRODUCT_ID", "FS_CARTON_ID", "PP_BOX_ID",
						"INX_CARTON_ID","SHEET_ID","PRODUCTGRADE","IQC_USER","SEAL_USER","OQC_USER","ETCHING_NO","POLISH_NO",
						"POLISH_PRESSURE","POLISH_TIME","CUTTING_NO","CLEAN_NO","THICKNESS_1","THICKNESS_2","THICKNESS_3",
						"THICKNESS_4","THICKNESS_5","THICKNESS_6","THICKNESS_7","THICKNESS_8"};
	            logger.info("building twqc_spc csv file process [" + fileName + "]");
	            CsvFileWriterUtil.writeCVS("SLIM_SPC_DATA_BEGIN", headers, bodyList, "SLIM_SPC_DATA_END", fileName);
	            logger.info("compress twqc_spc csv file process ....");
	            
	            ZipCompressUtil.compress(new File(fileName));
	            String gzFileName = fileName + ".zip";
	            SPCgzFile = new File(gzFileName);
	            // send to FTP Service
	            /*ftpTwqcService.connect();
	            ftpTwqcService.uploadFile(SPCgzFile, ftpTwqcService.getFtpConfigure().getFtpSpcExportPath());
	            ftpTwqcService.disconnectFtp();
	            logger.info("=============================================================================");*/
	        } catch (Exception e) {
	        	SPCFlag = false;
	        	e.printStackTrace();
	            logger.error(e.toString());
	            alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+e.toString());
	            throw e;
	        }
		}
		else if(type.equals("ECOA"))
		{
			List<String[]> bodyList = new ArrayList<String[]>();
	        for (Prod_ecoa entity : EcoaEntityList) {
	            String[] body = new String[] {entity.getSUPPLIER(),entity.getPRODUCT_ID(),entity.getCARTON_ID(),
	            		entity.getTARGET_THICKNESS(),entity.getIN_QTY_SHT(),entity.getIN_QTY_PANEL(),
	            		entity.getIN_NG_SHT_NON_PRCS(),entity.getIN_NEED_REPAIR_SHT(),entity.getIN_NG_SHT_BREAK(),
	            		entity.getETCH_QTY_SHT(),entity.getETCH_QTY_PANEL(),entity.getETCH_QTY_NG_SHT_BREAK(),
	            		entity.getETCH_QTY_NG_SHT_LEAK(),entity.getETCH_QTY_NG_SHT_CRACK(),entity.getTHICK_OVER_SPEC_SHT(),
	            		entity.getSHEET_YIELD(),entity.getPANEL_YIELD(),entity.getTPO_SHT_IN_SPEC(),entity.getTPO_SHT_OUT_SPEC(),
	            		entity.getSUPPLIER_SHT_IN_SPEC(),entity.getSUPPLIER_SHT_OUT_SPEC(),entity.getLOT_TYPE()};
	            logger.info(entity.toString());
	            bodyList.add(body);
	        }
			try {
				String fileName = ftpTwqcService.getFtpConfigure().getLocalEcoaGzPath().trim()+"/PROD_ECOA_" + getCurrentTimeStr() + ".csv";
				String[] headers = { "SUPPLIER", "PRODUCT_ID", "CARTON_ID", "TARGET_THICKNESS", "IN_QTY_SHT", "IN_QTY_PANEL",
						"IN_NG_SHT_NON_PRCS","IN_NEED_REPAIR_SHT","IN_NG_SHT_BREAK","ETCH_QTY_SHT","ETCH_QTY_PANEL","ETCH_QTY_NG_SHT_BREAK",
						"ETCH_QTY_NG_SHT_LEAK","ETCH_QTY_NG_SHT_CRACK","THICK_OVER_SPEC_SHT","SHEET_YIELD","PANEL_YIELD","TPO_SHT_IN_SPEC",
						"TPO_SHT_OUT_SPEC","SUPPLIER_SHT_IN_SPEC","SUPPLIER_SHT_OUT_SPEC","LOT_TYPE"};
	            logger.info("building twqc_ecoa csv file process [" + fileName + "]");
	            CsvFileWriterUtil.writeCVS("SLIM_ECOA_DATA_BEGIN", headers, bodyList, "SLIM_ECOA_DATA_END", fileName);
	            logger.info("compress twqc_ecoa csv file process ....");
	            
	            ZipCompressUtil.compress(new File(fileName));
	            String gzFileName = fileName + ".zip";
	            ECOAgzFile = new File(gzFileName);

	            // send to FTP Service
	            /*ftpTwqcService.connect();
	            ftpTwqcService.uploadFile(ECOAgzFile, ftpTwqcService.getFtpConfigure().getFtpEcoaExportPath());
	            ftpTwqcService.disconnectFtp();
	            logger.info("=============================================================================");*/
	        } catch (Exception e) {
	        	ECOAFlag = false;
	        	e.printStackTrace();
	            logger.error(e.toString());
	            alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+e.toString());
	            throw e;
	        }
		}
	}
	
	
	
	
	public void cutGlassProc(Ret_prd_info prd_info,TwqcMfgInfoXmlEntity mfgInfoXmlEntity,Ret_prd_in_twqc prd_in_twqc)
	{
		String product_id = prd_info.getPrd_seq_id().split("_")[0];
		String oxData = prd_in_twqc.getOXDATA().replace(",", "").replace("，","").trim();
        String cfOxInfo = prd_in_twqc.getCF_OX_INFO().replace(",", "").replace("，","").trim();
        String asmTestData = prd_in_twqc.getASMTESTDATA().replace(",", "").replace("，","").trim();
        //新增五个回传字段
        String arraytestreasoncode = "";
        String cftestreasoncode = "";
        String asmtestreasoncode = "";
        int good_cut_count = 0;//切割后的oxinfo，X以外的字符个数
        String tft_position = "";
        
        String arraytestreasoncodeArr[] = prd_in_twqc.getARRAYTESTREASONCODE().split(",", -1);
        String cftestreasoncodeArr[] = prd_in_twqc.getCFTESTREASONCODE().split(",", -1);
        String asmtestreasoncodeArr[] = prd_in_twqc.getASMTESTREASONCODE().split(",",-1);
        String tft_positionArr[] = prd_in_twqc.getTFT_POSITION().split(",", -1);
        
        //遍历数组并补全信息,才可以切割
        for(int i=0;i< arraytestreasoncodeArr.length;i++)
        {
        	if(arraytestreasoncodeArr[i].equals("")){
        		arraytestreasoncode = arraytestreasoncode+"     ";
        	}else{
        		arraytestreasoncode = arraytestreasoncode+arraytestreasoncodeArr[i];
        	}
        }
        for(int i=0;i<cftestreasoncodeArr.length;i++){
        	if(cftestreasoncodeArr[i].equals("")){
        		cftestreasoncode = cftestreasoncode+"     ";
        	}else{
        		cftestreasoncode = cftestreasoncode+cftestreasoncodeArr[i];
        	}
        }
        for(int i=0;i<asmtestreasoncodeArr.length;i++){
        	if(asmtestreasoncodeArr[i].equals("")){
        		asmtestreasoncode = asmtestreasoncode+"     ";
        	}else{
        		asmtestreasoncode = asmtestreasoncode+asmtestreasoncodeArr[i];
        	}
        }
        for(int i=0;i<tft_positionArr.length;i++){
        	if(tft_positionArr[i].equals("")){
        		tft_position = tft_position+"   ";
        	}else{
        		tft_position = tft_position+tft_positionArr[i];
        	}
        }
        /*String oxDefectCode = prd_in_twqc.getOXDEFECODE();
        String oxGrade = prd_in_twqc.getOXGRADE();
        String oxLevel = prd_in_twqc.getOXLEVEL();
        String tft_repair_flag = prd_in_twqc.getTFT_REPAIR_FLAG();*/
        
        
        //获取大板信息
        Ret_prd_info pv_ret_prd_info = retprdinfodao.getInforById(prd_info.getPv_prd_seq_id());
      		if(pv_ret_prd_info != null){
      			//获取pv mdl info
      			Bis_mdl_def pv_bis_mdl_def = bisMdlDefDao.getMdlDefListByMdlId(pv_ret_prd_info.getMdl_id_fk()).get(0);
      			if(pv_bis_mdl_def != null){
      				//获取切割设定
      				List<Bis_data> bis_dataList = bisDataDao.findBisData(pv_ret_prd_info.getMdl_id_fk(), pv_bis_mdl_def.getCut_typ(),prd_info.getMdl_id_fk());
      				for(Bis_data bis_data : bis_dataList){
      					String ext_1 = "";
    					if("Q1".equals(pv_bis_mdl_def.getCut_typ())){
    						ext_1 = prd_info.getPrd_seq_id().substring(prd_info.getPv_prd_seq_id().length() - bis_data.getExt_5().length());
    					}else{
    						ext_1 = prd_info.getPrd_seq_id().substring(prd_info.getPv_prd_seq_id().length());
    					}
      					if(ext_1.equals(bis_data.getExt_1())){
      						
      						//大板版式
      						int X = pv_ret_prd_info.getX_axis_cnt();
      						int Y = pv_ret_prd_info.getY_axis_cnt();
      						
      						//中板起始位置坐标
      						int start_Y = Integer.valueOf(bis_data.getExt_3());
      						int start_X = Integer.valueOf(bis_data.getExt_4());
      						
      						//开始切割的起始位置
      						int sta_pos = (start_Y-1) * X + start_X;
      						//切割后的版式
      						int cut_X = prd_info.getX_axis_cnt();
      						int cut_Y = prd_info.getY_axis_cnt();
      						
      						/* 定义四个字符代表一个panel的位置*//*int sta_pos4 = 0;
      						if(start_Y==1 && start_X==1){sta_pos4 = 1;}else{sta_pos4 = (start_Y-1) * X * 4 + start_X * 4;}
      						 * 定义两个字符代表一个panel的位置
      						int sta_pos2 = 0;
      						if(start_Y==1 && start_X==1)
      						{sta_pos2 = 1;}else{sta_pos2 = (start_Y-1) * X * 2 + start_X * 2;}*/
      						/*
      						 * 定义五个字符代表一个panel的位置
      						 */
      						int sta_pos5 = 0;
      						if(start_Y==1 && start_X==1)
      						{sta_pos5 = 1;}
      						else
      						{sta_pos5 = (start_Y-1) * X * 5 + start_X * 5;}
      						/*
      						 * 定义三个字符代表一个panel的位置
      						 */
      						int sta_pos3 = 0;
      						if(start_Y==1 && start_X==1)
      						{
      							sta_pos3 = 1;
      						}
      						else
      						{
      							sta_pos3 = (start_Y-1) * X * 3 + start_X * 3;
      						}
      						
      						
      						String OXDATA = "";
      						String CF_OX_INFO = "";
      						String ASMTESTDATA = "";
      						String ARRAYTESTREASONCODE = "";
      						String CFTESTREASONCODE = "";
      						String ASMTESTREASONCODE = "";
      						String TFT_POSITION = "";
      						/*String OXDEFECODE = "";
      						String OXGRADE = "";
      						String OXLEVEL = "";
      						String TFT_REPAIR_FLAG = "";*/
      						for(int i=0;i<cut_Y;i++)
      						{
      							//每次切割的起始位置和结束位置
      							int start_position = sta_pos+i*X-1;
      							int end_position = sta_pos+i*X+cut_X-1;
      							
      							if(end_position > oxData.length()){logger.info("oxdata字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"oxdata字符长度不够");IFDBFlag = false;return;}
      							if(end_position > cfOxInfo.length()){logger.info("cfOxInfo字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"cfOxInfo字符长度不够");IFDBFlag = false;return;}
      							if(end_position > asmTestData.length()){logger.info("asmTestData字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"asmTestData字符长度不够");IFDBFlag = false;return;}
      							if(sta_pos5+i*X*5+cut_X*5-5 > arraytestreasoncode.length()){logger.info("arraytestreasoncode字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"arraytestreasoncode字符长度不够");IFDBFlag = false;return;}
      							if(sta_pos5+i*X*5+cut_X*5-5 > cftestreasoncode.length()){logger.info("cftestreasoncode字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"cftestreasoncode字符长度不够");IFDBFlag = false;return;}
      							if(sta_pos5+i*X*5+cut_X*5-5 > asmtestreasoncode.length()){logger.info("asmtestreasoncode字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"asmtestreasoncode字符长度不够");IFDBFlag = false;return;}
      							if(sta_pos3+i*X*3+cut_X*3-3 > tft_position.length()){logger.info("tft_position字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"tft_position字符长度不够");IFDBFlag = false;return;}
      							/*if(i==cut_Y-1)
      							{
      								OXDATA = OXDATA + oxData.substring(start_position, end_position);
          							CF_OX_INFO = CF_OX_INFO + cfOxInfo.substring(start_position, end_position);
          							ASMTESTDATA = ASMTESTDATA + asmTestData.substring(start_position, end_position);
          							ARRAYTESTREASONCODE = ARRAYTESTREASONCODE + arraytestreasoncode.substring(sta_pos5+i*X*5-5, sta_pos5+i*X*5+cut_X*5-5);
          							CFTESTREASONCODE = CFTESTREASONCODE + cftestreasoncode.substring(sta_pos5+i*X*5-5, sta_pos5+i*X*5+cut_X*5-5);
          							ASMTESTREASONCODE = ASMTESTREASONCODE + asmtestreasoncode.substring(sta_pos5+i*X*5-5, sta_pos5+i*X*5+cut_X*5-5);
          							TFT_POSITION = TFT_POSITION + tft_position.substring(sta_pos3+i*X*3-3, sta_pos3+i*X*3+cut_X*3-3);
      							}
      							else{*/
      								OXDATA = OXDATA + oxData.substring(start_position, end_position);
          							CF_OX_INFO = CF_OX_INFO + cfOxInfo.substring(start_position, end_position);
          							ASMTESTDATA = ASMTESTDATA + asmTestData.substring(start_position, end_position);
          							if(sta_pos5==1 || sta_pos3==1 )
          							{
          								ARRAYTESTREASONCODE = ARRAYTESTREASONCODE + arraytestreasoncode.substring(sta_pos5+i*X*5-1, sta_pos5+i*X*5+cut_X*5-1);
              							CFTESTREASONCODE = CFTESTREASONCODE + cftestreasoncode.substring(sta_pos5+i*X*5-1, sta_pos5+i*X*5+cut_X*5-1);
              							ASMTESTREASONCODE = ASMTESTREASONCODE + asmtestreasoncode.substring(sta_pos5+i*X*5-1, sta_pos5+i*X*5+cut_X*5-1);
              							TFT_POSITION = TFT_POSITION + tft_position.substring(sta_pos3+i*X*3-1, sta_pos3+i*X*3+cut_X*3-1);
          							}
          							else{
          								ARRAYTESTREASONCODE = ARRAYTESTREASONCODE + arraytestreasoncode.substring(sta_pos5+i*X*5-5, sta_pos5+i*X*5+cut_X*5-5);
              							CFTESTREASONCODE = CFTESTREASONCODE + cftestreasoncode.substring(sta_pos5+i*X*5-5, sta_pos5+i*X*5+cut_X*5-5);
              							ASMTESTREASONCODE = ASMTESTREASONCODE + asmtestreasoncode.substring(sta_pos5+i*X*5-5, sta_pos5+i*X*5+cut_X*5-5);
              							TFT_POSITION = TFT_POSITION + tft_position.substring(sta_pos3+i*X*3-3, sta_pos3+i*X*3+cut_X*3-3);
          							}
      							//}
      							/*if(oxGrade.length()!=0)
      							{
      								if(end_position > oxGrade.length()){
      									logger.info("oxGrade字符长度不够");
      									alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"oxGrade字符长度不够");
      									return;
      								}
      								else{
      									OXGRADE = OXGRADE + oxGrade.substring(start_position, end_position);
      								}
      							}
      							if(end_position > tft_repair_flag.length()){logger.info("tft_repair_flag字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"tft_repair_flag字符长度不够");return;}
      							if(end_position*4 > oxDefectCode.length()){logger.info("oxDefectCode字符长度不够");
      							alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"oxDefectCode字符长度不够");return;}
      							if(oxLevel.length()!=0)
      							{
      								if(end_position*2 > oxLevel.length()){
      									logger.info("oxLevel字符长度不够");
      									alarmSenderService.sendAlarm1("232","栈板"+palletId+"回传失败\n"+"失败原因:"+"oxLevel字符长度不够");
      									return;
      								}
      								else{
      								//两个字符代表一个panel
              							OXLEVEL = OXLEVEL + oxLevel.substring(sta_pos2+i*X*2-2, sta_pos2+i*X*2+cut_X*2-2);
      								}
      							}
      							TFT_REPAIR_FLAG = TFT_REPAIR_FLAG + tft_repair_flag.substring(start_position, end_position);
      							四个字符代表一个panel
      							OXDEFECODE = OXDEFECODE + oxDefectCode.substring(sta_pos4+i*X*4-4, sta_pos4+i*X*4+cut_X*4-4);*/
      						}
      						int pv_length = OXDATA.length();
      						int cr_length = OXDATA.replace("X", "").length();
      						good_cut_count = OXDATA.replace(",", "").trim().length() -( pv_length - cr_length);
      						char[] oxdata = OXDATA.toCharArray();
      						char[] cf_ox_info = CF_OX_INFO.toCharArray();
      						char[] asmtestData = ASMTESTDATA.toCharArray();
      						String f_oxdata = "";
      						String f_cfOxInfo = "";
      						String f_asmTestData = "";
      						for(int i=0;i<oxdata.length;i++)
      						{
      							if(i!=oxdata.length-1){
      								f_oxdata = f_oxdata + String.valueOf(oxdata[i])+",";
      							}
      							else{
      								f_oxdata = f_oxdata + String.valueOf(oxdata[i]);
      							}
      						}
      						for(int i=0;i<cf_ox_info.length;i++)
      						{
      							if(i!=cf_ox_info.length-1){
      								f_cfOxInfo = f_cfOxInfo + String.valueOf(cf_ox_info[i])+",";
      							}
      							else{
      								f_cfOxInfo = f_cfOxInfo + String.valueOf(cf_ox_info[i]);
      							}
      						}
      						for(int i=0;i<asmtestData.length;i++)
      						{
      							if(i!=asmtestData.length-1){
      								f_asmTestData = f_asmTestData + String.valueOf(asmtestData[i])+",";
      							}
      							else{
      								f_asmTestData = f_asmTestData + String.valueOf(asmtestData[i]);
      							}
      						}
      						//TODO
      						ARRAYTESTREASONCODE = returnFormatStr(ARRAYTESTREASONCODE,5);
      						CFTESTREASONCODE = returnFormatStr(CFTESTREASONCODE,5);
      						ASMTESTREASONCODE = returnFormatStr(ASMTESTREASONCODE,5);
      						TFT_POSITION = returnFormatStr(TFT_POSITION,3);
      						
      						mfgInfoXmlEntity.setOXDATA(f_oxdata);
      						mfgInfoXmlEntity.setCF_OX_INFO(f_cfOxInfo);
      						mfgInfoXmlEntity.setASMTESTDATA(f_asmTestData);
      						mfgInfoXmlEntity.setARRAYTESTREASONCODE(ARRAYTESTREASONCODE);
      						mfgInfoXmlEntity.setCFTESTREASONCODE(CFTESTREASONCODE);
      						mfgInfoXmlEntity.setASMTESTREASONCODE(ASMTESTREASONCODE);
      						mfgInfoXmlEntity.setTFT_POSITION(TFT_POSITION);
      						mfgInfoXmlEntity.setGOOD_CUT_COUNT(good_cut_count);
      						/*mfgInfoXmlEntity.setOXDEFECODE(oxDefectCode);
      						mfgInfoXmlEntity.setOXGRADE(oxGrade);
      						mfgInfoXmlEntity.setOXLEVEL(oxLevel);
      						mfgInfoXmlEntity.setTFT_REPAIR_FLAG(tft_repair_flag);*/
      					}
      				}
      			}
      		}
	}
	
	public void setXmlEntity(TwqcMfgInfoXmlEntity mfgInfoXmlEntity,Ret_prd_in_twqc prd_in_twqc)
	{
		mfgInfoXmlEntity.setCHIP_QTY(prd_in_twqc.getCHIP_QTY());
		mfgInfoXmlEntity.setPPBOX_GRADE(prd_in_twqc.getPPBOX_GRADE()==null?"":prd_in_twqc.getPPBOX_GRADE());
		mfgInfoXmlEntity.setOXDATA(prd_in_twqc.getOXDATA()==null?"":prd_in_twqc.getOXDATA());
		mfgInfoXmlEntity.setCF_OX_INFO(prd_in_twqc.getCF_OX_INFO()==null?"":prd_in_twqc.getCF_OX_INFO());
		mfgInfoXmlEntity.setASMTESTDATA(prd_in_twqc.getASMTESTDATA()==null?"":prd_in_twqc.getASMTESTDATA());
		mfgInfoXmlEntity.setOXDEFECODE(prd_in_twqc.getOXDEFECODE()==null?"":prd_in_twqc.getOXDEFECODE());
		mfgInfoXmlEntity.setOXGRADE(prd_in_twqc.getOXGRADE()==null?"":prd_in_twqc.getOXGRADE());
		mfgInfoXmlEntity.setOXLEVEL(prd_in_twqc.getOXLEVEL()==null?"":prd_in_twqc.getOXLEVEL());
		mfgInfoXmlEntity.setTFT_REPAIR_FLAG(prd_in_twqc.getTFT_REPAIR_FLAG()==null?"":prd_in_twqc.getTFT_REPAIR_FLAG());
		mfgInfoXmlEntity.setDELIVERY_NO(prd_in_twqc.getDELIVERY_NO()==null?"":prd_in_twqc.getDELIVERY_NO());
		mfgInfoXmlEntity.setFACTORYID(prd_in_twqc.getFACTORYID()==null?"":prd_in_twqc.getFACTORYID());
		mfgInfoXmlEntity.setSHIPPINGFROM(prd_in_twqc.getSHIPPINGFROM()==null?"":prd_in_twqc.getSHIPPINGFROM());
		mfgInfoXmlEntity.setSHIPPINGTO(prd_in_twqc.getSHIPPINGTO()==null?"":prd_in_twqc.getSHIPPINGTO());
		mfgInfoXmlEntity.setFORCE_EMPTY(prd_in_twqc.getFORCE_EMPTY()==null?"":prd_in_twqc.getFORCE_EMPTY());
		mfgInfoXmlEntity.setPANEL_MODE(prd_in_twqc.getPANEL_MODE()==null?"":prd_in_twqc.getPANEL_MODE());
		mfgInfoXmlEntity.setERCODE(prd_in_twqc.getERCODE()==null?"":prd_in_twqc.getERCODE());
		mfgInfoXmlEntity.setERMESSAGE(prd_in_twqc.getERMESSAGE()==null?"":prd_in_twqc.getERMESSAGE());
		mfgInfoXmlEntity.setCT1FLAG(prd_in_twqc.getCT1FLAG()==null?"":prd_in_twqc.getCT1FLAG());
		mfgInfoXmlEntity.setPPBOX_COUNT(prd_in_twqc.getPPBOX_COUNT());
		mfgInfoXmlEntity.setGLASS_TYPE(prd_in_twqc.getGLASS_TYPE()==null?"":prd_in_twqc.getGLASS_TYPE());
		mfgInfoXmlEntity.setPE_PRODUCT_ID(prd_in_twqc.getPE_PRODUCT_ID()==null?"":prd_in_twqc.getPE_PRODUCT_ID());
		mfgInfoXmlEntity.setREJECT_REASON_CODE(prd_in_twqc.getREJECT_REASON_CODE()==null?"":prd_in_twqc.getREJECT_REASON_CODE());
		mfgInfoXmlEntity.setRETURN_COMMENT(prd_in_twqc.getRETURN_COMMENT()==null?"":prd_in_twqc.getRETURN_COMMENT());
		mfgInfoXmlEntity.setPALLET_OWNER(prd_in_twqc.getPALLET_OWNER()==null?"":prd_in_twqc.getPALLET_OWNER());
		mfgInfoXmlEntity.setPALLET_TYPE(prd_in_twqc.getPALLET_TYPE()==null?"":prd_in_twqc.getPALLET_TYPE());
		mfgInfoXmlEntity.setPALLET_ZONE_CODE(prd_in_twqc.getPALLET_ZONE_CODE()==null?"":prd_in_twqc.getPALLET_ZONE_CODE());
		mfgInfoXmlEntity.setPALLET_SET_CODE(prd_in_twqc.getPALLET_SET_CODE()==null?"":prd_in_twqc.getPALLET_SET_CODE());
		mfgInfoXmlEntity.setPP_BOX_ZONE_CODE(prd_in_twqc.getPP_BOX_ZONE_CODE()==null?"":prd_in_twqc.getPP_BOX_ZONE_CODE());
		mfgInfoXmlEntity.setPP_BOX_SETTING_CODE(prd_in_twqc.getPP_BOX_SETTING_CODE()==null?"":prd_in_twqc.getPP_BOX_SETTING_CODE());
		mfgInfoXmlEntity.setCONTAINER_NO(prd_in_twqc.getCONTAINER_NO()==null?"":prd_in_twqc.getCONTAINER_NO());
		mfgInfoXmlEntity.setFACTORYID_TO(prd_in_twqc.getFACTORYID_TO()==null?"":prd_in_twqc.getFACTORYID_TO());
		mfgInfoXmlEntity.setBOX_PN(prd_in_twqc.getBOX_PN()==null?"":prd_in_twqc.getBOX_PN());
		mfgInfoXmlEntity.setMES_SHIP_DATE(prd_in_twqc.getMES_SHIP_DATE()==null?"":prd_in_twqc.getMES_SHIP_DATE());
		mfgInfoXmlEntity.setORIGINALPRODUCT(prd_in_twqc.getORIGINALPRODUCT()==null?"":prd_in_twqc.getORIGINALPRODUCT());
		mfgInfoXmlEntity.setORIGINALPLAN(prd_in_twqc.getORIGINALPLAN()==null?"":prd_in_twqc.getORIGINALPLAN());
		mfgInfoXmlEntity.setORIGINALCELPARTNO(prd_in_twqc.getORIGINALCELPARTNO()==null?"":prd_in_twqc.getORIGINALCELPARTNO());
		mfgInfoXmlEntity.setORIGINALLOTID(prd_in_twqc.getORIGINALLOTID()==null?"":prd_in_twqc.getORIGINALLOTID());
		mfgInfoXmlEntity.setORIGINALLOTTYPE(prd_in_twqc.getORIGINALLOTTYPE()==null?"":prd_in_twqc.getORIGINALLOTTYPE());
		mfgInfoXmlEntity.setORIGINALBATCH(prd_in_twqc.getORIGINALBATCH()==null?"":prd_in_twqc.getORIGINALBATCH());
		mfgInfoXmlEntity.setORIGINALSIZE(prd_in_twqc.getORIGINALSIZE()==null?"":prd_in_twqc.getORIGINALSIZE());
		mfgInfoXmlEntity.setARRAYTESTREASONCODE(prd_in_twqc.getARRAYTESTREASONCODE()==null?"":prd_in_twqc.getARRAYTESTREASONCODE());
		mfgInfoXmlEntity.setARRAYTESTTXNTIME(prd_in_twqc.getARRAYTESTTXNTIME()==null?"":prd_in_twqc.getARRAYTESTTXNTIME());
		mfgInfoXmlEntity.setCFTESTREASONCODE(prd_in_twqc.getCFTESTREASONCODE()==null?"":prd_in_twqc.getCFTESTREASONCODE());
		mfgInfoXmlEntity.setCFTTESTTXNTIME(prd_in_twqc.getCFTTESTTXNTIME()==null?"":prd_in_twqc.getCFTTESTTXNTIME());
		mfgInfoXmlEntity.setASMTESTREASONCODE(prd_in_twqc.getASMTESTREASONCODE()==null?"":prd_in_twqc.getASMTESTREASONCODE());
		mfgInfoXmlEntity.setASMTESTTXNTIME(prd_in_twqc.getASMTESTTXNTIME()==null?"":prd_in_twqc.getASMTESTTXNTIME());
		mfgInfoXmlEntity.setCT1DATA(prd_in_twqc.getCT1DATA()==null?"":prd_in_twqc.getCT1DATA());
		mfgInfoXmlEntity.setCT1REASON(prd_in_twqc.getCT1REASON()==null?"":prd_in_twqc.getCT1REASON());
		mfgInfoXmlEntity.setCT1TESTTXNTIME(prd_in_twqc.getCT1TESTTXNTIME()==null?"":prd_in_twqc.getCT1TESTTXNTIME());
		mfgInfoXmlEntity.setCT2DATA(prd_in_twqc.getCT2DATA()==null?"":prd_in_twqc.getCT2DATA());
		mfgInfoXmlEntity.setCT2REASON(prd_in_twqc.getCT2REASON()==null?"":prd_in_twqc.getCT2REASON());
		mfgInfoXmlEntity.setCT2TESTTXNTIME(prd_in_twqc.getCT2TESTTXNTIME()==null?"":prd_in_twqc.getCT2TESTTXNTIME());
		mfgInfoXmlEntity.setCELL_REPAIR_FLAG(prd_in_twqc.getCELL_REPAIR_FLAG()==null?"":prd_in_twqc.getCELL_REPAIR_FLAG());
		mfgInfoXmlEntity.setENGINEERING(prd_in_twqc.getENGINEERING()==null?"":prd_in_twqc.getENGINEERING());
		mfgInfoXmlEntity.setQUADRANT(prd_in_twqc.getQUADRANT()==null?"":prd_in_twqc.getQUADRANT());
		mfgInfoXmlEntity.setOXFLAG(prd_in_twqc.getOXFLAG()==null?"":prd_in_twqc.getOXFLAG());
		mfgInfoXmlEntity.setOWNER(prd_in_twqc.getOWNER()==null?"":prd_in_twqc.getOWNER());
		mfgInfoXmlEntity.setTWO_CUT_DATE_TIME(prd_in_twqc.getTWO_CUT_DATE_TIME()==null?"":prd_in_twqc.getTWO_CUT_DATE_TIME());
		mfgInfoXmlEntity.setEXP_NO(prd_in_twqc.getEXP_NO()==null?"":prd_in_twqc.getEXP_NO());
		mfgInfoXmlEntity.setLASER_SHORT_RING_CUT(prd_in_twqc.getLASER_SHORT_RING_CUT()==null?"":prd_in_twqc.getLASER_SHORT_RING_CUT());
		mfgInfoXmlEntity.setRGB_DROP_HEIGHT(prd_in_twqc.getRGB_DROP_HEIGHT()==null?"":prd_in_twqc.getRGB_DROP_HEIGHT());
		mfgInfoXmlEntity.setPS_HEIGHT(prd_in_twqc.getPS_HEIGHT()==null?"":prd_in_twqc.getPS_HEIGHT());
		mfgInfoXmlEntity.setODF_PULSE(prd_in_twqc.getODF_PULSE()==null?"":prd_in_twqc.getODF_PULSE());
		mfgInfoXmlEntity.setSHEET_JUDGE(prd_in_twqc.getSHEET_JUDGE()==null?"":prd_in_twqc.getSHEET_JUDGE());
		mfgInfoXmlEntity.setTFT_DEFECT_CODE(prd_in_twqc.getTFT_DEFECT_CODE()==null?"":prd_in_twqc.getTFT_DEFECT_CODE());
		mfgInfoXmlEntity.setTFT_DEFECT_X(prd_in_twqc.getTFT_DEFECT_X()==null?"":prd_in_twqc.getTFT_DEFECT_X());
		mfgInfoXmlEntity.setTFT_DEFECT_Y(prd_in_twqc.getTFT_DEFECT_Y()==null?"":prd_in_twqc.getTFT_DEFECT_Y());
		mfgInfoXmlEntity.setCF_DEFECT_CODE(prd_in_twqc.getCF_DEFECT_CODE()==null?"":prd_in_twqc.getCF_DEFECT_CODE());
		mfgInfoXmlEntity.setCF_DEFECT_X(prd_in_twqc.getCF_DEFECT_X()==null?"":prd_in_twqc.getCF_DEFECT_X());
		mfgInfoXmlEntity.setCF_DEFECT_Y(prd_in_twqc.getCF_DEFECT_Y()==null?"":prd_in_twqc.getCF_DEFECT_Y());
		mfgInfoXmlEntity.setCF_POSITION(prd_in_twqc.getCF_POSITION()==null?"":prd_in_twqc.getCF_POSITION());
		mfgInfoXmlEntity.setLCD_PACK_TIME(prd_in_twqc.getLCD_PACK_TIME()==null?"":prd_in_twqc.getLCD_PACK_TIME());
		mfgInfoXmlEntity.setCF_GLASS_ID(prd_in_twqc.getCF_GLASS_ID()==null?"":prd_in_twqc.getCF_GLASS_ID());
		mfgInfoXmlEntity.setTFT_POLARIZER(prd_in_twqc.getTFT_POLARIZER()==null?"":prd_in_twqc.getTFT_POLARIZER());
		mfgInfoXmlEntity.setCF_POLARIZER(prd_in_twqc.getCF_POLARIZER()==null?"":prd_in_twqc.getCF_POLARIZER());
		mfgInfoXmlEntity.setGOOD_CUT_COUNT(prd_in_twqc.getGOOD_CUT_COUNT());
		mfgInfoXmlEntity.setCUT_OX_INFO(prd_in_twqc.getCUT_OX_INFO()==null?"":prd_in_twqc.getCUT_OX_INFO());
		mfgInfoXmlEntity.setUPDFLAG(prd_in_twqc.getUPDFLAG()==null?"":prd_in_twqc.getUPDFLAG());
		mfgInfoXmlEntity.setUPDUSER(prd_in_twqc.getUPDUSER()==null?"":prd_in_twqc.getUPDUSER());
		mfgInfoXmlEntity.setUPDTIME(prd_in_twqc.getUPDTIME()==null?"":prd_in_twqc.getUPDTIME());
		mfgInfoXmlEntity.setINPUT_STATUS(prd_in_twqc.getINPUT_STATUS()==null?"":prd_in_twqc.getINPUT_STATUS());
		mfgInfoXmlEntity.setLC_DROPPED(prd_in_twqc.getLC_DROPPED()==null?"":prd_in_twqc.getLC_DROPPED());
		mfgInfoXmlEntity.setABNORMAL_TFT(prd_in_twqc.getABNORMAL_TFT()==null?"":prd_in_twqc.getABNORMAL_TFT());
		mfgInfoXmlEntity.setABNORMAL_CF(prd_in_twqc.getABNORMAL_CF()==null?"":prd_in_twqc.getABNORMAL_CF());
		mfgInfoXmlEntity.setABNORMAL_LCD(prd_in_twqc.getABNORMAL_LCD()==null?"":prd_in_twqc.getABNORMAL_LCD());
		mfgInfoXmlEntity.setGOOD_CHIP_COUNT(prd_in_twqc.getGOOD_CHIP_COUNT()==null?"":prd_in_twqc.getGOOD_CHIP_COUNT());
		mfgInfoXmlEntity.setTWO_CUTTING_DATE_TIME(prd_in_twqc.getTWO_CUTTING_DATE_TIME()==null?"":prd_in_twqc.getTWO_CUTTING_DATE_TIME());
		mfgInfoXmlEntity.setQ_DATE_TIME(prd_in_twqc.getQ_DATE_TIME()==null?"":prd_in_twqc.getQ_DATE_TIME());
		mfgInfoXmlEntity.setQ_TIME_RESET_CNT(prd_in_twqc.getQ_TIME_RESET_CNT()==null?"":prd_in_twqc.getQ_TIME_RESET_CNT());
		mfgInfoXmlEntity.setLCD_PRODUCT_ID(prd_in_twqc.getLCD_PRODUCT_ID()==null?"":prd_in_twqc.getLCD_PRODUCT_ID());
		mfgInfoXmlEntity.setFORMAT_ID(prd_in_twqc.getFORMAT_ID()==null?"":prd_in_twqc.getFORMAT_ID());
		mfgInfoXmlEntity.setRISK_FLAG_CODE(prd_in_twqc.getRISK_FLAG_CODE()==null?"":prd_in_twqc.getRISK_FLAG_CODE());
		mfgInfoXmlEntity.setABNORMAL_LCM(prd_in_twqc.getABNORMAL_LCM()==null?"":prd_in_twqc.getABNORMAL_LCM());
		mfgInfoXmlEntity.setSERIAL_NO(prd_in_twqc.getSERIAL_NO()==null?"":prd_in_twqc.getSERIAL_NO());
		mfgInfoXmlEntity.setSERIAL_NO_CUST(prd_in_twqc.getSERIAL_NO_CUST()==null?"":prd_in_twqc.getSERIAL_NO_CUST());
		mfgInfoXmlEntity.setREVISION(prd_in_twqc.getREVISION()==null?"":prd_in_twqc.getREVISION());
		mfgInfoXmlEntity.setLCM_CARTON_GRADE(prd_in_twqc.getLCM_CARTON_GRADE()==null?"":prd_in_twqc.getLCM_CARTON_GRADE());
		mfgInfoXmlEntity.setLCM_GRADE(prd_in_twqc.getLCM_GRADE()==null?"":prd_in_twqc.getLCM_GRADE());
		mfgInfoXmlEntity.setDFCT_LIST(prd_in_twqc.getDFCT_LIST()==null?"":prd_in_twqc.getDFCT_LIST());
		mfgInfoXmlEntity.setWO_CUSTOMER(prd_in_twqc.getWO_CUSTOMER()==null?"":prd_in_twqc.getWO_CUSTOMER());
		mfgInfoXmlEntity.setFINAL_CUSTOMER(prd_in_twqc.getFINAL_CUSTOMER()==null?"":prd_in_twqc.getFINAL_CUSTOMER());
		mfgInfoXmlEntity.setAERB_NO(prd_in_twqc.getAERB_NO()==null?"":prd_in_twqc.getAERB_NO());
		mfgInfoXmlEntity.setPI_GROUP_ID(prd_in_twqc.getPI_GROUP_ID()==null?"":prd_in_twqc.getPI_GROUP_ID());
		mfgInfoXmlEntity.setPE_QTY(prd_in_twqc.getPE_QTY()==null?"":prd_in_twqc.getPE_QTY());
		mfgInfoXmlEntity.setSHIPPING_COUNT_TYPE(prd_in_twqc.getSHIPPING_COUNT_TYPE()==null?"":prd_in_twqc.getSHIPPING_COUNT_TYPE());
		mfgInfoXmlEntity.setGOOD_PNL_COUNT(prd_in_twqc.getGOOD_PNL_COUNT()==null?"":prd_in_twqc.getGOOD_PNL_COUNT());
		mfgInfoXmlEntity.setITO_FLAG(prd_in_twqc.getITO_FLAG()==null?"":prd_in_twqc.getITO_FLAG());
		mfgInfoXmlEntity.setTOD_GRADE(prd_in_twqc.getTOD_GRADE()==null?"":prd_in_twqc.getTOD_GRADE());
		mfgInfoXmlEntity.setCST_ID(prd_in_twqc.getCST_ID()==null?"":prd_in_twqc.getCST_ID());
		mfgInfoXmlEntity.setCST_ZONE_CODE(prd_in_twqc.getCST_ZONE_CODE()==null?"":prd_in_twqc.getCST_ZONE_CODE());
		mfgInfoXmlEntity.setCST_SETTING_CODE(prd_in_twqc.getCST_SETTING_CODE()==null?"":prd_in_twqc.getCST_SETTING_CODE());
		mfgInfoXmlEntity.setTFT_POSITION(prd_in_twqc.getTFT_POSITION()==null?"":prd_in_twqc.getTFT_POSITION());
		mfgInfoXmlEntity.setIN_STOCK_DATE(prd_in_twqc.getIN_STOCK_DATE()==null?"":prd_in_twqc.getIN_STOCK_DATE());
		mfgInfoXmlEntity.setCUT_FLAG(prd_in_twqc.getCUT_FLAG()==null?"":prd_in_twqc.getCUT_FLAG());
		mfgInfoXmlEntity.setSUBSTRATE_POSITION_ID(prd_in_twqc.getSUBSTRATE_POSITION_ID()==null?"":prd_in_twqc.getSUBSTRATE_POSITION_ID());
		mfgInfoXmlEntity.setCF_SUBSTRATE_POSITION_ID(prd_in_twqc.getCF_SUBSTRATE_POSITION_ID()==null?"":prd_in_twqc.getCF_SUBSTRATE_POSITION_ID());
		mfgInfoXmlEntity.setCUT_POSITION_ID(prd_in_twqc.getCUT_POSITION_ID()==null?"":prd_in_twqc.getCUT_POSITION_ID());
		mfgInfoXmlEntity.setCUT_CF_POSITION_ID(prd_in_twqc.getCUT_CF_POSITION_ID()==null?"":prd_in_twqc.getCUT_CF_POSITION_ID());
		mfgInfoXmlEntity.setPTT_GRADE(prd_in_twqc.getPTT_GRADE()==null?"":prd_in_twqc.getPTT_GRADE());
		mfgInfoXmlEntity.setTFT_STB_DATE(prd_in_twqc.getTFT_STB_DATE()==null?"":prd_in_twqc.getTFT_STB_DATE());
		mfgInfoXmlEntity.setTFT_STB_TIME(prd_in_twqc.getTFT_STB_TIME()==null?"":prd_in_twqc.getTFT_STB_TIME());
		mfgInfoXmlEntity.setLCD_EXP_NO(prd_in_twqc.getLCD_EXP_NO()==null?"":prd_in_twqc.getLCD_EXP_NO());
		mfgInfoXmlEntity.setLCD_ENG_NAME(prd_in_twqc.getLCD_ENG_NAME()==null?"":prd_in_twqc.getLCD_ENG_NAME());
		mfgInfoXmlEntity.setTFT_ABN_APPLY_TO(prd_in_twqc.getTFT_ABN_APPLY_TO()==null?"":prd_in_twqc.getTFT_ABN_APPLY_TO());
		mfgInfoXmlEntity.setCF_ABN_APPLY_TO(prd_in_twqc.getCF_ABN_APPLY_TO()==null?"":prd_in_twqc.getCF_ABN_APPLY_TO());
		mfgInfoXmlEntity.setLCD_ABN_APPLY_TO(prd_in_twqc.getLCD_ABN_APPLY_TO()==null?"":prd_in_twqc.getLCD_ABN_APPLY_TO());
		mfgInfoXmlEntity.setCF_STB_DATE(prd_in_twqc.getCF_STB_DATE()==null?"":prd_in_twqc.getCF_STB_DATE());
		mfgInfoXmlEntity.setCF_STB_TIME(prd_in_twqc.getCF_STB_TIME()==null?"":prd_in_twqc.getCF_STB_TIME());
		mfgInfoXmlEntity.setODF_MOVE_OUT_DATE_TIME(prd_in_twqc.getODF_MOVE_OUT_DATE_TIME()==null?"":prd_in_twqc.getODF_MOVE_OUT_DATE_TIME());
		mfgInfoXmlEntity.setCST_ABNORMAL_TFT(prd_in_twqc.getCST_ABNORMAL_TFT()==null?"":prd_in_twqc.getCST_ABNORMAL_TFT());
		mfgInfoXmlEntity.setCST_ABNORMAL_CF(prd_in_twqc.getCST_ABNORMAL_CF()==null?"":prd_in_twqc.getCST_ABNORMAL_CF());
		mfgInfoXmlEntity.setCST_ABNORMAL_LCD(prd_in_twqc.getCST_ABNORMAL_LCD()==null?"":prd_in_twqc.getCST_ABNORMAL_LCD());
		mfgInfoXmlEntity.setDEFECT_CODE(prd_in_twqc.getDEFECT_CODE()==null?"":prd_in_twqc.getDEFECT_CODE());
		mfgInfoXmlEntity.setRESET_2_CUT_DATE_TIME(prd_in_twqc.getRESET_2_CUT_DATE_TIME()==null?"":prd_in_twqc.getRESET_2_CUT_DATE_TIME());
		mfgInfoXmlEntity.setDN_ITEM(prd_in_twqc.getDN_ITEM()==null?"":prd_in_twqc.getDN_ITEM());
		mfgInfoXmlEntity.setGLASS_WITH_CHIP_ID(prd_in_twqc.getGLASS_WITH_CHIP_ID()==null?"":prd_in_twqc.getGLASS_WITH_CHIP_ID());
		mfgInfoXmlEntity.setRISK_LOT_ID(prd_in_twqc.getRISK_LOT_ID()==null?"":prd_in_twqc.getRISK_LOT_ID());
		mfgInfoXmlEntity.setLC_PART_NO(prd_in_twqc.getLC_PART_NO()==null?"":prd_in_twqc.getLC_PART_NO());
		mfgInfoXmlEntity.setPROCESSED_GLASSID(prd_in_twqc.getPROCESSED_GLASSID()==null?"":prd_in_twqc.getPROCESSED_GLASSID());
		mfgInfoXmlEntity.setREF_DELIVERY_NO(prd_in_twqc.getREF_DELIVERY_NO()==null?"":prd_in_twqc.getREF_DELIVERY_NO());
	}
	public String returnFormatStr(String Str,int length)
	{
		//TODO
		char StrArr[] = Str.toCharArray();
		String resultStr = "";
		if(length==5)
		{
			for(int i=5;i<StrArr.length;i++)
			{
				if(i%5==0 && i!=StrArr.length-1){
					resultStr = resultStr + StrArr[i-5]+StrArr[i-4]+StrArr[i-3]+StrArr[i-2]+StrArr[i-1]+",";
				}else if(i==StrArr.length-1){
					resultStr = resultStr + StrArr[i-4]+StrArr[i-3]+StrArr[i-2]+StrArr[i-1]+StrArr[i];
				}
			}
		}
		if(length==3)
		{
			for(int i=3;i<StrArr.length;i++)
			{
				if(i%3==0 && i!=StrArr.length-1){
					resultStr = resultStr + StrArr[i-3]+StrArr[i-2]+StrArr[i-1]+",";
				}else if(i==StrArr.length-1){
					resultStr = resultStr +StrArr[i-2]+StrArr[i-1]+StrArr[i];
				}
			}
		}
		return resultStr.replace(" ", "");
	}
	public String getCurrentTimeStr()
	{
		Timestamp currentTime = TimeUtil.getCurrentTimestamp();
		String timeStr = currentTime.toString();
		String YYYYMMDD = timeStr.substring(0, 10).replace("-", "");
        String HHMMSS = timeStr.substring(11,19).replace(":", "");
        return YYYYMMDD+HHMMSS;
	}
	
	public String getFormatTimeStr(String timeStr)
	{
		String YYYYMMDD = timeStr.substring(0, 10).replace("-", "");
        String HHMMSS = timeStr.substring(11,19).replace(":", "");
        return YYYYMMDD+HHMMSS;
	}
	
	public String getFormatTimeStr2(Timestamp time)
	{
		String timeStr = time.toString();
		String YYYYMMDD = timeStr.substring(0, 10).replace("-", "");
        String YYYY = YYYYMMDD.substring(0, 4);
        String MM = YYYYMMDD.substring(4,6);
        String DD = YYYYMMDD.substring(6,8);
        return YYYY+"/"+MM+"/"+DD;
	}
	
	public String getFileName()
	{
		Timestamp currentTime = TimeUtil.getCurrentTimestamp();
		String timeStr = currentTime.toString();
		String YYYYMMDD = timeStr.substring(0, 10).replace("-", "");
		String localPath = ftpTwqcService.getFtpConfigure().getLocalGzPath();
		
		File file = new File(localPath);
	    File[] tempList = file.listFiles();
	    int first_num = 0;//记录当前目录中当天已经含有的流水码
	    int new_num = 0;
	    int num_flag = 0;
	    int max_num = 0;
	    boolean flag = false;//标记是否有当天的文件
	    if(tempList.length != 0)
	    {
	    	for (int i = 0; i < tempList.length; i++) {
		        if (tempList[i].isFile()) {
		            String fileName = tempList[i].getName();
		            if(fileName.endsWith(".zip"))
		            {
		            	if(YYYYMMDD.equals(fileName.substring(0,8)))
		            	{
		            		flag = true;
		            		//重新运行，目录中已经含有当天文件，获取最大的流水码
		            		if(num_flag == 0)
		            		{
		            			//第一个文件的流水码
		            			first_num = Integer.parseInt(fileName.substring(9,11));
		            			num_flag++;
		            		}
		            		else{
		            			new_num = Integer.parseInt(fileName.substring(9,11));
		            		}
		            		//取到文件的后缀最大值
		            		max_num = new_num > first_num ? new_num : first_num;
		            		first_num = max_num;
		            	}
		            }
		        }
		    }
	    }else{
	    	randomNum = 1;
	    }
	    if(flag==true)
	    {
	    	//找到了当天的文件
	    	randomNum = max_num+1;
	    }
	    else{randomNum = 1;}
		String ranNum = "";
		if(randomNum<10)
		{
			ranNum = "0"+randomNum;
		}
		else
		{
			ranNum = String.valueOf(randomNum);
		}
		return YYYYMMDD+"-"+ranNum+".XML";
	}
}
